<?php

/**
* alltosun.com 收货地址控制器 index.php
* ============================================================================
* 版权所有 (C) 2009-2014 北京互动阳光科技有限公司，并保留所有权利。
* 网站地址: http://www.alltosun.com
* ----------------------------------------------------------------------------
* 许可声明: 这是一个开源程序，未经许可不得将本软件的整体或任何部分用于商业用途及再发布。
* ============================================================================
* $Author: 吴松键 (wusj@alltosun.com) $
* $Date: 2014-9-4 上午9:22:02 $
* $Id$
*/

class Action
{
    private $user_id;

    public function __construct()
    {
        $this->user_id = user_helper::get_user_id();
//         if (!$this->user_id) {
//             Response::redirect(AnUrl('index'));
//             return '登录超时';
//         }
    }

    public function index()
    {
        Response::display('index.html');
    }

    public function get_provincial()
    {
        $parent_id = Request::getParam('parent_id', '');

        if (!(int)$parent_id) {
            if (is_numeric($parent_id) && $parent_id == 0) {
                $parent_id = 0;
            } else {
                return array();
            }
        }

        return $list = _model('provincial')->getList(array('parent_id'=>(int)$parent_id, 'status'=>1));
    }

    public function update_address()
    {
        $ids = _model('address')->getFields('district_id', array('id >'=>0));

        echo join($ids, ',');
    }

    public function add_provincial()
    {
        $config = provincial_config::$config;
//         print_r($config);
        foreach ($config as $k=>$v) {
            $a = substr($k, 0, 2);
            $b = substr($k, 2, 2);
            $c = substr($k, 4);
            $code = '';
            $filter = array(
                    'code'=>$k,
                    'title'=>$v
            );

            if ($v == '市辖区') {
                $filter['status'] = '0';
            }

            if ($c == '00' && $b != '00') {
                // 市辖区
                $code = $a.'0000';
            }
            if ($c != '00' && $b != '00') {
                $code = $a.$b.'00';
                if ($a == '11' || $a == '12' || $a == '31' || $a == '50') {
                    $code = $a.'0100';
                }
            }

            if (!$code) {
                $filter['parent_id'] = '0';
                $filter['path'] = '0';
            } else {
                $p_info = _uri('provincial', array('code'=>$code));
                $filter['parent_id'] = $p_info['id'];
                $filter['path'] = $p_info['path'].'-'.$p_info['id'];
            }
            $info = _uri('provincial', $filter);
            if (!empty($info)) {
                continue;
            }
//             _model('provincial')->create($filter);
        }

    }

    public function p()
    {
        $config = provincial_config::$new_config;
//                 print_r($config);

        $p = array();
        foreach ($config as $k=>$v) {
            $p[$v[0]] = $v[1];
        }
        $p_config = array();
        foreach ($p as $k=>$v) {
            $id = '';
            $info = array(
                    'code'=>$k,
                    'title'=>$v,
                    'parent_id'=>0,
                    'path'=>0,
            );
//             $id = _model('provincial')->create($info);
            $p_config[$v] = $id;
        }

        foreach ($p_config as $k=>$v) {
            echo '\''.$k.'\'=>\''.$v.'\','.'<br>';
        }

    }

    public function c()
    {
        $config = provincial_config::$new_config;
        $p_config = array(
                '北京'=>'1',
                '上海'=>'2',
                '天津'=>'3',
                '内蒙古'=>'4',
                '山西'=>'5',
                '河北'=>'6',
                '辽宁'=>'7',
                '吉林'=>'8',
                '黑龙江'=>'9',
                '江苏'=>'10',
                '安徽'=>'11',
                '山东'=>'12',
                '浙江'=>'13',
                '江西'=>'14',
                '福建'=>'15',
                '湖南'=>'16',
                '湖北'=>'17',
                '河南'=>'18',
                '广东'=>'19',
                '海南'=>'20',
                '广西'=>'21',
                '贵州'=>'22',
                '四川'=>'23',
                '云南'=>'24',
                '陕西'=>'25',
                '甘肃'=>'26',
                '宁夏'=>'27',
                '青海'=>'28',
                '新疆'=>'29',
                '西藏'=>'30',
                '重庆'=>'31',
                '深圳'=>'32',
        );
        $c = array();
        foreach ($config as $k=>$v) {
            $c[$v[2]] = $p_config[$v[1]];
        }

        $c_config = array();
        foreach ($c as $k=>$v) {
            $id = '';
            $info = array(
                    'title'=>$k,
                    'parent_id'=>$v,
                    'path'=>'0-'.$v,
            );
//             $id = _model('provincial')->create($info);
            $c_config[$k] = $id;
        }

        foreach ($c_config as $k=>$v) {
            echo '\''.$k.'\'=>\''.$v.'\','.'<br>';
        }
    }

    public function a()
    {
        $config = provincial_config::$new_config;
        $c_config = array(
                '北京'=>'33',
                '上海'=>'34',
                '天津'=>'35',
                '阿拉善'=>'36',
                '巴彦淖尔'=>'37',
                '包头'=>'38',
                '赤峰'=>'39',
                '鄂尔多斯'=>'40',
                '呼和浩特'=>'41',
                '呼伦贝尔'=>'42',
                '通辽'=>'43',
                '乌海'=>'44',
                '乌兰察布'=>'45',
                '锡林郭勒'=>'46',
                '兴安盟'=>'47',
                '长治'=>'48',
                '大同'=>'49',
                '晋城'=>'50',
                '晋中'=>'51',
                '临汾'=>'52',
                '吕梁'=>'53',
                '朔州'=>'54',
                '太原'=>'55',
                '忻州'=>'56',
                '阳泉'=>'57',
                '运城'=>'58',
                '保定'=>'59',
                '沧州'=>'60',
                '承德'=>'61',
                '邯郸'=>'62',
                '衡水'=>'63',
                '开平'=>'64',
                '廊坊'=>'65',
                '秦皇岛'=>'66',
                '石家庄'=>'67',
                '唐山'=>'68',
                '邢台'=>'69',
                '张家口'=>'70',
                '鞍山'=>'71',
                '本溪'=>'72',
                '朝阳'=>'73',
                '大连'=>'74',
                '丹东'=>'75',
                '抚顺'=>'76',
                '阜新'=>'77',
                '葫芦岛'=>'78',
                '锦州'=>'79',
                '辽阳'=>'80',
                '盘锦'=>'81',
                '沈阳'=>'82',
                '铁岭'=>'83',
                '营口'=>'84',
                '白城'=>'85',
                '白山'=>'86',
                '长春'=>'87',
                '吉林'=>'88',
                '九台'=>'89',
                '辽源'=>'90',
                '农安'=>'91',
                '四平'=>'92',
                '松原'=>'93',
                '通化'=>'94',
                '延边'=>'95',
                '大庆'=>'96',
                '大兴安岭'=>'97',
                '哈尔滨'=>'98',
                '鹤岗'=>'99',
                '黑河'=>'100',
                '鸡西'=>'101',
                '佳木斯'=>'102',
                '牡丹江'=>'103',
                '七台河'=>'104',
                '齐齐哈尔'=>'105',
                '双鸭山'=>'106',
                '绥化'=>'107',
                '伊春'=>'108',
                '常州'=>'109',
                '淮安'=>'110',
                '连云港'=>'111',
                '南京'=>'112',
                '南通'=>'113',
                '苏州'=>'114',
                '宿迁'=>'115',
                '泰州'=>'116',
                '无锡'=>'117',
                '徐州'=>'118',
                '盐城'=>'119',
                '扬州'=>'120',
                '镇江'=>'121',
                '安庆'=>'122',
                '蚌埠'=>'123',
                '池州'=>'124',
                '滁州'=>'125',
                '阜阳'=>'126',
                '毫州'=>'127',
                '合肥'=>'128',
                '淮北'=>'129',
                '淮南'=>'130',
                '黄山'=>'131',
                '六安'=>'132',
                '马鞍山'=>'133',
                '宿州'=>'134',
                '铜陵'=>'135',
                '芜湖'=>'136',
                '宣城'=>'137',
                '滨州'=>'138',
                '德州'=>'139',
                '东营'=>'140',
                '菏泽'=>'141',
                '济南'=>'142',
                '济宁'=>'143',
                '莱芜'=>'144',
                '聊城'=>'145',
                '临沂'=>'146',
                '青岛'=>'147',
                '日照'=>'148',
                '泰安'=>'149',
                '威海'=>'150',
                '潍坊'=>'151',
                '烟台'=>'152',
                '枣庄'=>'153',
                '淄博'=>'154',
                '杭州'=>'155',
                '湖州'=>'156',
                '嘉兴'=>'157',
                '金华'=>'158',
                '丽水'=>'159',
                '宁波'=>'160',
                '衢州'=>'161',
                '绍兴'=>'162',
                '台州'=>'163',
                '温州'=>'164',
                '舟山'=>'165',
                '抚州'=>'166',
                '赣州'=>'167',
                '吉安'=>'168',
                '景德镇'=>'169',
                '九江'=>'170',
                '南昌'=>'171',
                '萍乡'=>'172',
                '上饶'=>'173',
                '新余'=>'174',
                '宜春'=>'175',
                '鹰潭'=>'176',
                '福州'=>'177',
                '龙岩'=>'178',
                '南平'=>'179',
                '宁德'=>'180',
                '莆田'=>'181',
                '泉州'=>'182',
                '三明'=>'183',
                '厦门'=>'184',
                '漳州'=>'185',
                '长沙'=>'186',
                '常德'=>'187',
                '郴州'=>'188',
                '衡阳'=>'189',
                '怀化'=>'190',
                '娄底'=>'191',
                '邵阳'=>'192',
                '湘潭'=>'193',
                '湘西'=>'194',
                '益阳'=>'195',
                '永州'=>'196',
                '岳阳'=>'197',
                '张家界'=>'198',
                '株洲'=>'199',
                '鄂州'=>'200',
                '恩施'=>'201',
                '黄冈'=>'202',
                '黄石'=>'203',
                '荆门'=>'204',
                '荆州'=>'205',
                '潜江'=>'206',
                '神农架林区'=>'207',
                '十堰'=>'208',
                '随州'=>'209',
                '天门'=>'210',
                '武汉'=>'211',
                '仙桃'=>'212',
                '咸宁'=>'213',
                '襄阳'=>'214',
                '孝感'=>'215',
                '宜昌'=>'216',
                '安阳'=>'217',
                '鹤壁'=>'218',
                '济源'=>'219',
                '焦作'=>'220',
                '开封'=>'221',
                '洛阳'=>'222',
                '漯河'=>'223',
                '南阳'=>'224',
                '平顶山'=>'225',
                '濮阳'=>'226',
                '三门峡'=>'227',
                '商丘'=>'228',
                '新乡'=>'229',
                '信阳'=>'230',
                '许昌'=>'231',
                '郑州'=>'232',
                '周口'=>'233',
                '驻马店'=>'234',
                '潮州'=>'235',
                '东莞'=>'236',
                '佛山'=>'237',
                '广州'=>'238',
                '河源'=>'239',
                '惠州'=>'240',
                '江门'=>'241',
                '揭阳'=>'242',
                '茂名'=>'243',
                '梅州'=>'244',
                '清远'=>'245',
                '汕头'=>'246',
                '汕尾'=>'247',
                '韶关'=>'248',
                '深圳'=>'249',
                '阳江'=>'250',
                '云浮'=>'251',
                '湛江'=>'252',
                '肇庆'=>'253',
                '中山'=>'254',
                '珠海'=>'255',
                '海口'=>'256',
                '陵水'=>'257',
                '百色'=>'258',
                '北海'=>'259',
                '崇左'=>'260',
                '防城港'=>'261',
                '贵港'=>'262',
                '桂林'=>'263',
                '河池'=>'264',
                '贺州'=>'265',
                '来宾'=>'266',
                '柳州'=>'267',
                '南宁'=>'268',
                '钦州'=>'269',
                '梧州'=>'270',
                '玉林'=>'271',
                '安顺'=>'272',
                '毕节'=>'273',
                '贵阳'=>'274',
                '六盘水'=>'275',
                '黔东南'=>'276',
                '黔南'=>'277',
                '黔西南'=>'278',
                '铜仁'=>'279',
                '遵义'=>'280',
                '阿坝'=>'281',
                '巴中'=>'282',
                '成都'=>'283',
                '达州'=>'284',
                '德阳'=>'285',
                '甘孜'=>'286',
                '广安'=>'287',
                '广元'=>'288',
                '乐山'=>'289',
                '凉山'=>'290',
                '泸州'=>'291',
                '眉山'=>'292',
                '绵阳'=>'293',
                '内江'=>'294',
                '南充'=>'295',
                '攀枝花'=>'296',
                '遂宁'=>'297',
                '雅安'=>'298',
                '宜宾'=>'299',
                '资阳'=>'300',
                '自贡'=>'301',
                '保山'=>'302',
                '楚雄'=>'303',
                '大理'=>'304',
                '德宏'=>'305',
                '迪庆'=>'306',
                '红河'=>'307',
                '昆明'=>'308',
                '丽江'=>'309',
                '临沧'=>'310',
                '怒江'=>'311',
                '曲靖'=>'312',
                '思茅'=>'313',
                '文山'=>'314',
                '西双版纳'=>'315',
                '玉溪'=>'316',
                '昭通'=>'317',
                '安康'=>'318',
                '宝鸡'=>'319',
                '汉中'=>'320',
                '商洛'=>'321',
                '铜川'=>'322',
                '渭南'=>'323',
                '西安'=>'324',
                '咸阳'=>'325',
                '延安'=>'326',
                '榆林'=>'327',
                '白银'=>'328',
                '定西'=>'329',
                '甘南'=>'330',
                '嘉峪关'=>'331',
                '金昌'=>'332',
                '酒泉'=>'333',
                '兰州'=>'334',
                '临夏'=>'335',
                '陇南'=>'336',
                '平凉'=>'337',
                '庆阳'=>'338',
                '天水'=>'339',
                '武威'=>'340',
                '张掖'=>'341',
                '固原'=>'342',
                '石嘴山'=>'343',
                '吴忠'=>'344',
                '银川'=>'345',
                '中卫'=>'346',
                '果洛'=>'347',
                '海北'=>'348',
                '海东'=>'349',
                '海南'=>'350',
                '海西'=>'351',
                '黄南'=>'352',
                '西宁'=>'353',
                '玉树'=>'354',
                '阿克苏'=>'355',
                '阿拉尔'=>'356',
                '阿勒泰'=>'357',
                '巴音郭楞'=>'358',
                '北屯'=>'359',
                '博尔塔拉'=>'360',
                '昌吉'=>'361',
                '哈密'=>'362',
                '和田'=>'363',
                '喀什'=>'364',
                '克拉玛依'=>'365',
                '克孜勒苏柯尔克孜'=>'366',
                '石河子'=>'367',
                '塔城'=>'368',
                '图木舒克'=>'369',
                '吐鲁番'=>'370',
                '乌鲁木齐'=>'371',
                '五家渠'=>'372',
                '伊犁'=>'373',
                '阿里'=>'374',
                '昌都'=>'375',
                '拉萨'=>'376',
                '林芝'=>'377',
                '那曲'=>'378',
                '日喀则'=>'379',
                '山南'=>'380',
                '重庆'=>'381',
                'NULL'=>'382',
        );
        $a = array();
        foreach ($config as $k=>$v) {
            $a[$v[3]] = $c_config[$v[2]];
        }

        foreach ($a as $k=>$v) {
            $id = '';
            $info = array(
                    'title'=>$k,
                    'parent_id'=>$v,
            );
            $parent_id = _uri('provincial', $v, 'parent_id');
            $info['path'] = '0-'.$parent_id.'-'.$v;

//             _model('provincial')->create($info);
        }
    }

}
?>